import 'package:film/controller/auth_controller.dart';
import 'package:film/controller/film_all_controlle.dart';
import 'package:film/controller/film_rank_controller.dart';
import 'package:film/controller/film_search_controller.dart';
import 'package:film/controller/film_week_controller.dart';
import 'package:film/controller/follow_film_controller.dart';
import 'package:film/controller/home_controller.dart';
import 'package:film/controller/login_controller.dart';
import 'package:film/controller/mine_controller.dart';
import 'package:film/controller/share_controller.dart';
import 'package:film/controller/vip_controller.dart';
import 'package:film/screen/film_all_screen.dart';
import 'package:film/screen/film_rank_screen.dart';
import 'package:film/screen/film_screen.dart';
import 'package:film/screen/film_search_screen.dart';
import 'package:film/screen/film_week_screen.dart';
import 'package:film/screen/follow_film_screen.dart';
import 'package:film/screen/login_screen.dart';
import 'package:film/screen/member_screen.dart';
import 'package:film/screen/tab_screen.dart';
import 'package:film/screen/vip_screen.dart';
import 'package:film/screen/message_screen.dart';
import 'package:film/controller/message_controller.dart';
import 'package:film/service/api_service.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:get/get.dart';
import 'package:get_storage/get_storage.dart';
import 'package:film/screen/update_password_screen.dart';
import 'package:film/controller/update_password_controller.dart';
import 'package:film/screen/play_record_screen.dart';
import 'package:film/controller/play_record_controller.dart';
import 'package:film/screen/forgot_password_screen.dart';
import 'package:film/controller/forgot_password_controller.dart';
import 'package:super_player/super_player.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  String licenceURL = "https://license.vod2.myqcloud.com/license/v2/1259776471_1/v_cube.license";
  String licenceKey = "75c73c21ba45154b62138cbd94358854";
  SuperPlayerPlugin.setGlobalLicense(licenceURL, licenceKey);
  await GetStorage.init();
  final box = GetStorage();
  String token = box.read('token') ?? '';
  DioClient.setAuthToken(token);
  final DioService apiService = DioService();
  ApiResponse<UserInfo?> response = await apiService.getUserInfo();
  AuthController authController = Get.put(AuthController());
  if (response.success) {
    if (response.code == '001') {
      await authController.getUserInfo();
      authController.loginFlag.value = true;
    }
  }
  SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
  Get.put(HomeController());
  Get.put(ShareController());
  Get.put(MineController());
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  final DioService apiService = DioService();
  MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return GetMaterialApp(
      title: '动漫',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.white),
      ),
      initialRoute: '/tab',
      // home: VlcPlayerScreen(
      //     videoUrl:
      //         'https://cn-beijing-data.aliyundrive.net/sIoGJqZD%2F1772963%2F67f7d6a4fc4486615668405db3a6c678230c1b85%2F67f7d6a401fda2a9e6704b5dbb1f2ed86f867d9d?callback=eyJjYWxsYmFja1VybCI6Imh0dHA6Ly9iajI5LmFwaS1ocC5hbGl5dW5wZHMuY29tL3YyL2ZpbGUvZG93bmxvYWRfY2FsbGJhY2siLCJjYWxsYmFja0JvZHkiOiJodHRwSGVhZGVyLnJhbmdlPSR7aHR0cEhlYWRlci5yYW5nZX1cdTAwMjZidWNrZXQ9JHtidWNrZXR9XHUwMDI2b2JqZWN0PSR7b2JqZWN0fVx1MDAyNmRvbWFpbl9pZD0ke3g6ZG9tYWluX2lkfVx1MDAyNnVzZXJfaWQ9JHt4OnVzZXJfaWR9XHUwMDI2ZHJpdmVfaWQ9JHt4OmRyaXZlX2lkfVx1MDAyNmZpbGVfaWQ9JHt4OmZpbGVfaWR9XHUwMDI2cGRzX3BhcmFtcz0ke3g6cGRzX3BhcmFtc31cdTAwMjZ2ZXJzaW9uPSR7eDp2ZXJzaW9ufSIsImNhbGxiYWNrQm9keVR5cGUiOiJhcHBsaWNhdGlvbi94LXd3dy1mb3JtLXVybGVuY29kZWQiLCJjYWxsYmFja1N0YWdlIjoiYmVmb3JlLWV4ZWN1dGUiLCJjYWxsYmFja0ZhaWx1cmVBY3Rpb24iOiJpZ25vcmUifQ%3D%3D&callback-var=eyJ4OmRvbWFpbl9pZCI6ImJqMjkiLCJ4OnVzZXJfaWQiOiJlMDYxOWNkOGZlMDY0MjY5OTdhNmFkNzYxNTAzNGJiOSIsIng6ZHJpdmVfaWQiOiIxNzcyOTYzIiwieDpmaWxlX2lkIjoiNjdmN2Q2YTRmYzQ0ODY2MTU2Njg0MDVkYjNhNmM2NzgyMzBjMWI4NSIsIng6cGRzX3BhcmFtcyI6IntcImFwXCI6XCI3NWY0NzBjNDhmYzU0ZGU0YThmMzZiZDE1MTFhNzQ3YlwifSIsIng6dmVyc2lvbiI6InYzIn0%3D&di=bj29&dr=1772963&f=67f7d6a4fc4486615668405db3a6c678230c1b85&pds-params=%7B%22ap%22%3A%2275f470c48fc54de4a8f36bd1511a747b%22%7D&response-content-disposition=attachment%3B%20filename%2A%3DUTF-8%27%27e9fd674a-01&security-token=CAISvgJ1q6Ft5B2yfSjIr5r5Iu7Mn55Q37Sgb0PU13Qma9ZWpY3frjz2IHhMf3NpBOkZvvQ1lGlU6%2Fcalq5rR4QAXlDfNUjxHTXFq1HPWZHInuDox55m4cTXNAr%2BIhr%2F29CoEIedZdjBe%2FCrRknZnytou9XTfimjWFrXWv%2Fgy%2BQQDLItUxK%2FcCBNCfpPOwJms7V6D3bKMuu3OROY6Qi5TmgQ41Uh1jgjtPzkkpfFtkGF1GeXkLFF%2B97DRbG%2FdNRpMZtFVNO44fd7bKKp0lQLs0ARrv4r1fMUqW2X543AUgFLhy2KKMPY99xpFgh9a7j0iCbSGyUu%2FhcRm5sw9%2Byfo34lVYneQzHCRx%2Fni4IClLcc%2BmqdsRIvJzWstJ7Gf9LWqChvSgk4TxhhcNFKSTQrInFCB0%2BcRObJl16iN47%2BWPXtuMkagAFnYyKJ7RchgNH5432uxtwsCWRlbcbCsyhwzMPsOr8u%2FMGlx9jT56rWaKutnuqrpT2XQe43vbDXiKRPV1Z%2FK416dp2Io6NFm9a%2BfMeOcL2APzwan04eZuANMQMrVmdY%2F%2FZ%2Bqu3wg3aFMoIhDQSVRM1AV7Jav%2F8Kd9RtyiAF7K%2FdvSAA&u=e0619cd8fe06426997a6ad7615034bb9&x-oss-access-key-id=STS.NYLiTxrAqhvKmee3tsgYzJHtL&x-oss-expires=1750775598&x-oss-signature=j8%2BGGPFfav3%2BrCCoxNv8Jtc9nqQa0Q0Cycy84Wgm0h4%3D&x-oss-signature-version=OSS2'),
      localizationsDelegates: [
        GlobalMaterialLocalizations.delegate,
        GlobalCupertinoLocalizations.delegate,
        GlobalWidgetsLocalizations.delegate,
      ],
      debugShowCheckedModeBanner: false,
      supportedLocales: [
        Locale.fromSubtags(languageCode: 'en'),
        Locale.fromSubtags(languageCode: 'zh'),
      ],
      locale: const Locale('zh'),
      getPages: [
        GetPage(
          name: '/tab',
          page: () => TabScreen(),
        ),
        GetPage(
          name: '/login',
          page: () => LoginScreen(),
          binding: BindingsBuilder(() {
            Get.lazyPut<LoginController>(() => LoginController());
          }),
        ),
        GetPage(
          name: '/film',
          page: () => FilmScreen(),
          // binding: BindingsBuilder(() {
          //   Get.lazyPut<FilmController>(() => FilmController());
          // }),
        ),
        GetPage(
          name: '/filmAll',
          page: () => FilmAllScreen(),
          binding: BindingsBuilder(() {
            Get.lazyPut<FilmAllController>(() => FilmAllController());
          }),
        ),
        GetPage(
          name: '/filmWeek',
          page: () => FilmWeekScreen(),
          binding: BindingsBuilder(() {
            Get.lazyPut<FilmWeekController>(() => FilmWeekController());
          }),
        ),
        GetPage(
          name: '/vip',
          page: () => VipScreen(),
          binding: BindingsBuilder(() {
            Get.lazyPut<VipController>(() => VipController());
          }),
        ),
        GetPage(
          name: '/message',
          page: () => MessageScreen(),
          binding: BindingsBuilder(() {
            Get.lazyPut<MessageController>(() => MessageController());
          }),
        ),
        GetPage(
          name: '/updatePassword',
          page: () => UpdatePasswordScreen(),
          binding: BindingsBuilder(() {
            Get.lazyPut<UpdatePasswordController>(() => UpdatePasswordController());
          }),
        ),
        GetPage(
          name: '/playRecord',
          page: () => PlayRecordScreen(),
          binding: BindingsBuilder(() {
            Get.lazyPut<PlayRecordController>(() => PlayRecordController());
          }),
        ),
        GetPage(
          name: '/followFilm',
          page: () => FollowFilmScreen(),
          binding: BindingsBuilder(() {
            Get.lazyPut<FollowFilmController>(() => FollowFilmController());
          }),
        ),
        GetPage(
          name: '/forgotPassword',
          page: () => ForgotPasswordScreen(),
          binding: BindingsBuilder(() {
            Get.lazyPut<ForgotPasswordController>(() => ForgotPasswordController());
          }),
        ),
        GetPage(
          name: '/filmSearch',
          page: () => FilmSearchScreen(),
          binding: BindingsBuilder(() {
            Get.lazyPut<FilmSearchController>(() => FilmSearchController());
          }),
        ),
        GetPage(
          name: '/filmRank',
          page: () => FilmRankScreen(),
          binding: BindingsBuilder(() {
            Get.lazyPut<FilmRankController>(() => FilmRankController());
          }),
        ),
        GetPage(
          name: '/member',
          page: () => MemberScreen(),
          binding: BindingsBuilder(() {
            Get.lazyPut<MemberScreen>(() => MemberScreen());
          }),
        )
      ],
    );
  }
}
